#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2022, Andrey Kunitsyn
# Copyright (c) 2022, Nikolay Semenov
#
# This file is part of the modm project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# -----------------------------------------------------------------------------

def init(module):
    module.name = ":board:thingplus-rp2040"
    module.description = """\
# SparkFun Thing Plus - RP2040

The SparkFun Thing Plus - RP2040 is a low-cost, high performance board
with flexible digital interfaces featuring the Raspberry Pi Foundation's RP2040 microcontroller.
Besides the Thing Plus or Feather footprint (with 18 GPIO pins),
the board also includes an SD card slot, 16MB (128Mbit) flash memory,
a JST single cell battery connector (with a charging circuit and fuel gauge sensor),
an addressable WS2812 RGB LED, JTAG PTH pins, four (4-40 screw) mounting holes,
and SparkFun's Qwiic connector.

https://www.sparkfun.com/products/17745

See `modm:rp-pico` for programming instructions.
"""

def prepare(module, options):
    if not options[":target"].partname.startswith("rp2040"):
        return False

    module.depends(
        ":platform:clock",
        ":platform:core",
        ":platform:gpio",
        ":platform:usb",
        ":platform:clockgen")
    return True

def build(env):
    env.outbasepath = "modm/src/modm/board"
    env.substitutions = {
        "with_logger": False,
        "with_assert": env.has_module(":architecture:assert")
    }
    env.template("../board.cpp.in", "board.cpp")
    env.copy('.')

    env.outbasepath = "modm/openocd/modm/board/"
    env.copy(repopath("tools/openocd/modm/rp2040_picoprobe.cfg"), "rp2040_picoprobe.cfg")
    env.collect(":build:openocd.source", "modm/board/rp2040_picoprobe.cfg")
